import React, { Component } from 'react'
import PubSub from 'pubsub-js';

export default class LOLHeader extends Component {

    state = {
        keywords: ''
    }

    render() {
        return (
            <div className="form">
                <input type="text" onChange={this.change} value={this.state.keywords} />
                <button onClick={this.search}>搜索</button>
            </div>
        )
    }
    //搜索功能
    search = () => {
        // this.state.keywords 输入的关键字
        PubSub.publish('search', this.state.keywords);
    }

    //改变input元素值的回调
    change = (e) => {
        this.setState({
            keywords: e.target.value
        })
    }




}
